package com.iring.controller.admin;

import java.util.List;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.iring.controller.BaseController;
import com.iring.domain.common.OperationType;
import com.iring.domain.common.view.ConsumptionView;
import com.iring.vo.common.BooleanResultVO;
import com.iring.vo.common.ConsumpVO;
import com.iring.vo.user.AlarmVO;

/**
 * 消费记录Controller
 *
 * @author wanggan
 */

@RestController
@RequestMapping(value = "/admin/consumption", produces = { "application/json;charset=UTF-8" })
public class ConsumptionController extends BaseController {

    /**
     * 获取所有的消费类型
     *
     * @return 所有的消费类型
     */
    @RequestMapping(value = "/list-all-consumption-type", method = RequestMethod.POST)
    public List<OperationType> listAllConsumptionType() {
        return operationTypeDao.findAll();
    }

    /**
     * 通过消费类型和时间进行筛选
     *
     * @param consumpVO
     *            {@link ConsumpVO}
     * @return 返回消费记录列表信息
     */
    @RequestMapping(value = "/list-consumption-detail", method = RequestMethod.POST)
    public List<ConsumptionView> listConsumptionDetail(@RequestBody ConsumpVO consumpVO) {
        return consumptionService.listConsumptionDetail(getUserSession().getUsername(), consumpVO);
    }

    /**
     * 修改用户的是否余额告警提示信息
     *
     * @param alarmVO
     *            {@link AlarmVO}
     * @return 修改结果
     */
    @RequestMapping(value = "/is-open-alarm", method = RequestMethod.POST)
    public BooleanResultVO isOpenAlarm(@RequestBody AlarmVO alarmVO) {
        String username = getUserSession().getUsername();
        userService.isOpenAlarm(username, alarmVO);
        logService.saveLog(username,"modify alarm",getUserRealIp(),true);
        return new BooleanResultVO(Boolean.TRUE);
    }
}
